Imports System.Drawing

Namespace Overlay
    ''' <summary>
    ''' The jChart.Overlay.ScatterOverlay object is used to chart scatter series. Series must be 
    ''' of type jChart.Overlay.Series.ScatterSeries
    ''' </summary>
    ''' <remarks></remarks>
    Public Class ScatterOverlay
        Inherits OverLayBase

        ''' <summary>
        ''' oChartDimensions is a jChart.ChartDimensions object that describes the interior of 
        ''' the chart. oXAxis and oYAxis are the X and Y axes that should be used for series 
        ''' belonging to the OverLay object.
        ''' </summary>
        ''' <param name="oChartDimensions"></param>
        ''' <param name="oXAxis"></param>
        ''' <param name="oYAxis"></param>
        ''' <remarks></remarks>
        Public Sub New( _
            ByVal oChartDimensions As ChartDimensions, _
            ByVal oXAxis As XAxis, _
            ByVal oYAxis As YAxis)

            MyBase.New(oChartDimensions, oXAxis, oYAxis)
        End Sub

        Protected Overrides Sub DrawAllSeries(ByRef g As Graphics)
            '---Count all series
            For Each oSeries As Series.ScatterSeries In moSeries
                '---Draw point
                DrawIndicator(g, oSeries)
            Next
        End Sub

        Protected Sub DrawIndicator( _
                            ByVal g As Graphics, _
                            ByVal oSeries As Series.ScatterSeries)

            '---Find center point of indicator
            Dim iXPos As Integer = moXAxis.CalculateXPos(oSeries.XValue)
            Dim iYpos As Integer = moYAxis.CalculateYPos(oSeries.YValue)

            Dim oIndicatorFactory As New IndicatorFactory()
            oIndicatorFactory.Draw( _
                            oIndicator:=oSeries.Indicator, _
                            g:=g, _
                            iXPos:=iXPos, _
                            iYPos:=iYpos, _
                            iDiameterWidth:=oSeries.IndicatorWidth, _
                            iDiameterHeight:=oSeries.IndicatorHeight, _
                            iOpacity:=oSeries.Opacity)

            AddIndicatorToRegion(iXPos, iYpos, oSeries)
        End Sub

        Protected Sub AddIndicatorToRegion( _
                            ByVal iXPos As Integer, _
                            ByVal iYPos As Integer, _
                            ByVal oSeries As Series.ScatterSeries)

            Dim oPolygonPoints(3) As Point

            '--Upper-left
            With oPolygonPoints(0)
                .X = iXPos - (oSeries.IndicatorWidth / 2)
                .Y = iYPos - (oSeries.IndicatorHeight / 2)
            End With

            '--Upper-right
            With oPolygonPoints(1)
                .X = iXPos + (oSeries.IndicatorWidth / 2)
                .Y = iYPos - (oSeries.IndicatorHeight / 2)
            End With

            '---Lower-right
            With oPolygonPoints(2)
                .X = iXPos + (oSeries.IndicatorWidth / 2)
                .Y = iYPos + (oSeries.IndicatorHeight / 2)
            End With

            '---Lower-left
            With oPolygonPoints(3)
                .X = iXPos - (oSeries.IndicatorWidth / 2)
                .Y = iYPos + (oSeries.IndicatorHeight / 2)
            End With

            Dim oRegion As New RegionArea(oSeries.Name, oSeries.XValue, oSeries.YValue, oPolygonPoints)
            moRegionList.Add(oRegion)
        End Sub


    End Class
End Namespace